<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>

<script type="text/javascript">
    wx.config({
      debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
      appId: '{$appId}', // 必填，公众号的唯一标识
      timestamp: {$timestamp}, // 必填，生成签名的时间戳
      nonceStr: '{$nonceStr}', // 必填，生成签名的随机串
      signature: '{$signature}',// 必填，签名，见附录1
      jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','chooseImage'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
    });

    wx.ready(function(){

      wx.onMenuShareTimeline({
          title: '{$title}', // 分享标题
          link: '{$url}', // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          imgUrl: 'http://1o533n8683.imwork.net/P201703/bbs/Uploads/pic/2017-08-01/597ff1242bcfb.jpg', // 分享图标
          success: function () { 
              alert(888)
          },
          cancel: function () { 
              alert(999)
          }
      });
    });

    function openxbs () {
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
            }
        });
  }
    window.onload = function  () {
        xbsopen = document.getElementById('xbsopen');
        xbsopen.oncilck = function  () {
          alert(88)
          // wx.chooseImage({
          //     count: 1, // 默认9
          //     sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
          //     sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
          //     success: function (res) {
          //         var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
          //     }
          // });
        }
    }
</script>

<div class="main layui-clear">
  <div class="wrap">
    <div class="content detail">
      <div class="fly-panel detail-box">
        <h1><?php echo $ques['title']; ?></h1>
        <div class="fly-tip fly-detail-hint">
          <span><?php echo $ques['status']; ?></span>
          <input type="button" onclick="openxbs()" value="打相册">
          <div class="jie-admin-box" data-id="12140"></div>
          <div class="fly-list-hint">
            <a href="#comment">
              <i class="iconfont" title="回答">&#xe60c;</i><?php echo $ques['answer_num']; ?></a>
            <i class="iconfont" title="人气">&#xe60b;</i><?php echo $ques['view_num']; ?></div></div>
        <div class="detail-about">
          <a class="jie-user" href="/u/5888568/">
            <img src="__ROOT__/<?php echo $ques['face']; ?>" alt="<?php echo $ques['nickname']; ?>">
            <cite><?php echo $ques['nickname']; ?>
              <em>发布于<?php echo Ctime($ques['create_time']) ?></em></cite>
          </a>
          <div class="detail-hits" id="LAY_jieAdmin" data-id="12140">
            <span style="color:#FF7200">悬赏：<?php echo $ques['kiss']; ?>飞吻</span>

            <?php if($collect){ ?>
                <span id="collect" class="layui-btn layui-btn-mini jie-admin layui-btn-danger" qid="<?php echo $ques['qid'] ?>" type="collect" data-type="add">取消收藏</span>
            <?php }else{ ?>
                <span id="collect" class="layui-btn layui-btn-mini jie-admin " qid="<?php echo $ques['qid'] ?>" type="collect" data-type="add">收藏</span>
            <?php } ?>
            
            <!-- <span class="layui-btn layui-btn-mini jie-admin  layui-btn-danger" type="collect" data-type="add">取消收藏</span> -->
            </div>
        </div>
        <div class="detail-body photos"><?php echo htmlspecialchars_decode($ques['content']); ?></div></div>
      <div class="fly-panel detail-box" style="padding-top: 0;">
        <ul class="jieda photos" id="jieda">
          <?php if($answers) { ?>
              <?php foreach ($answers as  $row) { ?>
                  <li data-id="42006">
                    <a name="item-1501555798385"></a>
                    <div class="detail-about detail-about-reply">
                      <a class="jie-user" href="{:U('home/u/index',array('id'=>$row['uid']))}">
                        <img src="__ROOT__/<?php echo $row['face'] ?>" alt="yuanwei">
                        <cite>
                          <i><?php echo $row['nickname'] ?></i>
                        </cite>
                      </a>
                      <div class="detail-hits">
                        <span><?php echo Ctime($row['create_time']) ?></span></div>
                    </div>
                    <div class="detail-body jieda-body">
                      <?php echo htmlspecialchars_decode($row['content']) ?>
                    </div>
                    <div class="jieda-reply">
                      <span class="jieda-zan <?php if($row['is_zan']){ echo 'zanok'; } ?>" type="zan" aid="<?php echo $row['aid'] ?>">
                        <i class="iconfont icon-zan"></i>
                        <em><?php echo $row['zan_num'] ?></em></span>
                      <span type="reply">
                        <i class="iconfont icon-svgmoban53"></i>回复</span>
                    </div>
                  </li>
              <?php } ?>
          <?php }else{ ?>
              <li class="fly-none">没有任何回答</li>
          <?php }?>
        </ul>
        <div class="layui-form layui-form-pane">
          <form action="" method="post">
            <div class="layui-form-item layui-form-text">
              <a name="comment"></a>
              <div class="layui-input-block">
                <textarea id="L_content" name="content" required  placeholder="我要回答" class="layui-textarea fly-editor" style="height: 150px;"></textarea>
              </div>
            </div>
            <div class="layui-form-item">
              <input type="hidden" name="qid" value="<?php echo $_GET['id'] ?>">
              <button class="layui-btn" lay-filter="answeradd" lay-submit>提交回答</button></div>
          </form>
        </div>
      </div>
    </div>
  </div>
  <div class="edge">
    <dl class="fly-panel fly-list-one">
      <dt class="fly-panel-title">近期热议</dt>
      <?php foreach ($hotQues as  $row) { ?>
        <dd>
          <a href="{:U('home/jie/index',array('id'=>$row['qid']))}"><?php echo $row['title'] ?></a>
          <span>
            <i class="iconfont">&#xe60c;</i><?php echo $row['answer_num'] ?></span>
        </dd>
      <?php } ?>
    </dl>
  </div>
</div>
<script>
    layui.use(['form','jquery','layedit'], function(){
      var form = layui.form();
      $ = layui.jquery;
      var layedit = layui.layedit;

      layedit.set({
        uploadImage: {
          url: '{:U('home/jie/upload')}' //接口url
          ,type: '' //默认post
        }
      });

      index = layedit.build('L_content'); //建立编辑器

      
      //监听提交
      form.on('submit(answeradd)', function(data){
       
        data.field.content = layedit.getContent(index);
        // // layer.msg(JSON.stringify(data.field));

        $.ajax({
          url: '{:U('home/jie/answeradd')}',
          type: 'POST',
          dataType: 'json',
          data: data.field,
        })
        .done(function(res) {
           if(res.error==1){
              layer.msg(res.info,function(){});
           }else{
              layer.alert(res.info, {icon: 6},function(){
                  location.reload();
              });
           }
        })
        .fail(function() {
          console.log("error");
        })

        return false;

      });


      $('#collect').click(function(event) {
          qid = $(this).attr('qid');

          that = $(this);

          $.ajax({
            url: '{:U('home/jie/collect')}',
            type: 'post',
            dataType: 'json',
            data: {qid:qid},
          })
          .done(function(res) {
            if(res.error==0){
              that.addClass('layui-btn-danger');
              that.text('取消收藏');
            }else{
              that.removeClass('layui-btn-danger');
              that.text('收藏');
            }

          })
          .fail(function() {

            
          })
      });

      $('.jieda-zan').click(function(event) {
          aid = $(this).attr('aid');

          that = $(this);

          $.ajax({
            url: '{:U('home/jie/zan')}',
            type: 'post',
            dataType: 'json',
            data: {aid: aid},
          })
          .done(function(res) {
            if(res.error==0){
              num = parseInt(that.children('em').text())+1;
              that.children('em').text(num);
              that.addClass('zanok');
            }else{
              num = parseInt(that.children('em').text())-1;
              that.children('em').text(num);
              that.removeClass('zanok');
            }

          })
          .fail(function() {

            
          })
      });

    });
</script>